﻿#include "jinchegnxuanse.h"
#include "ui_jinchegnxuanse.h"

jinchegnxuanse::jinchegnxuanse(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::jinchegnxuanse)
{
    ui->setupUi(this);
}

jinchegnxuanse::~jinchegnxuanse()
{
    delete ui;
}


void jinchegnxuanse::processlist()
{
    //创建系统进程快照
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot) {
        PROCESSENTRY32 pe32;
        pe32.dwSize = sizeof(PROCESSENTRY32);

        // 获取快照中第一个进程的信息
        if (Process32First(hSnapshot, &pe32)) {
            do {
                // 打印进程名称
               QTreeWidgetItem *k = new QTreeWidgetItem();
               QString File = QString::fromWCharArray(pe32.szExeFile);
               QString ID = QString::number(pe32.th32ProcessID);
               k->setText(1,File);
               k->setText(0,ID);
               ui->treeWidget->addTopLevelItem(k);
               // std::wcout << pe32.szExeFile <<pe32.th32ProcessID << std::endl;
            } while (Process32Next(hSnapshot, &pe32)); // 继续获取下一个进程的信息
        };
        CloseHandle(hSnapshot); // 关闭快照对象
    };

}
void jinchegnxuanse::removeprocesslist()
{
    ui->treeWidget->clear();
}

void jinchegnxuanse::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
    processID = item->text(0).toUInt();
    processName = item->text(1);
    emit itemDClicked();//将进程选择信号发送
    //emit itemDClicked1();
}

